<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
        var Test = (function(){
           var name = "aa"
            var Test = function(){};
            Test.prototype.aa = function(){
                console.log(name);
            };
            Test.prototype.setAa = function(){
                name = "bb";
            };
            return Test;
        })();

        var test = new Test();
        test.aa();
        test.setAa();
        debugger;

        var Foo = function(){};

        Foo.prototype.aa = Test.prototype.aa;

        var foo = new Foo();
        //原型上扩展aa，调用的aa的this已经变成foo，但是aa的闭包作用域中仍然后name
        foo.aa();

        var Too = function(){};

        var too = new Too();
        too.aa = Test.prototype.aa;
        //对象上扩展aa，调用的aa的this已经变成too，但是aa的闭包作用域中仍然后name
        too.aa();

    </script>
</head>
<body>

</body>
</html>